#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    int mincostTickets(vector<int> &days, vector<int> &costs)
    {
        vector<int> minCost(days.size() + 1, 0);
        int indexWeek = 0, indexMounth = 0;
        for (int i = 1; i < days.size() + 1; i++)
        {
            // for day ticket
            minCost[i] = minCost[i - 1] + costs[0];
            // for week ticket
            while (indexWeek < i && days[indexWeek] < days[i - 1] - 6)
            {
                indexWeek++;
            }
            if (indexWeek < i )
                minCost[i] = min(minCost[i], minCost[indexWeek] + costs[1]);
            // for mounth ticket
            while (indexMounth < i && days[indexMounth] < days[i - 1] - 29)
            {
                indexMounth++;
            }
            if (indexMounth < i)
                minCost[i] = min(minCost[i], minCost[indexMounth] + costs[2]);
        }
        return minCost[days.size()];
    }
};

int main()
{
    cout << "Code983" << endl;
    Solution s;
    vector<int> days = {1, 4, 6, 7, 8, 20};
    vector<int> costs = {7, 2, 15};
    cout << s.mincostTickets(days, costs) << endl;
    return 0;
}